var ZWItems;

var vm = new Vue({
    el: "#app",
    data: function () {
        return {
            ID:"",
            // 接下来绑定数据，分别对应前面的列的key值来进行数据绑定
            data1: [],
            // 初始化信息总条数
            dataCount:0,
            StandAreaTotal:"",
            //展位信息end
            formItem:{
                Store:"",
                Bm:"",
                ID:"",
                Name:"",
                Sex:"",
                Tel1:"",
                Tel2:"",
                Fixtel:"",
                Province:"",
                City:"",
                County:"",
                Jiguan:"",
                CardNo:"",
                Birthday:"",
                YinOrYang:"",
                PastDaiBrand:"",
                ZsProgress:"",
                PastDaiBrand:"",
                StartTime:"",
                Relations:"",
                ShStar:"",
                ProductType:""
            },
            zwItem: ZWItems,
            stripe: true,
            StoreTypeList:[
                {
                    value: '东明店面',
                    label: '东明店面'
                },
                {
                    value: '红星美凯龙',
                    label: '红星美凯龙'
                },
                {
                    value: '居然之家',
                    label: '居然之家'
                },
                {
                    value: '怀特',
                    label: '怀特'
                },
                {
                    value: '米氏',
                    label: '米氏'
                },
                {
                    value: '蓝天',
                    label: '蓝天'
                },
                {
                    value: '明月',
                    label: '明月'
                },
                {
                    value: '正定金河',
                    label: '正定金河'
                },
                {
                    value: '正定三才',
                    label: '正定三才'
                },
            ],
            StoreList: [],
            ProductTypeList:[
                {
                    value: '软体家具',
                    label: '软体家具'
                },
                {
                    value: '板式板木家具',
                    label: '板式板木家具'
                },
                {
                    value: '实木家具',
                    label: '实木家具'
                },
                {
                    value: '欧式家具',
                    label: '欧式家具'
                },
                {
                    value: '红木家具',
                    label: '红木家具'
                },
                {
                    value: '儿童家具',
                    label: '儿童家具'
                },
                {
                    value: '定制家具',
                    label: '定制家具'
                },
                {
                    value: '小件、家纺',
                    label: '小件、家纺'
                },
                {
                    value: '办公家具',
                    label: '办公家具'
                },
                {
                    value: '建材、异业',
                    label: '建材、异业'
                },
                {
                    value: '智能家具',
                    label: '智能家具'
                },
                {
                    value: '户外家具',
                    label: '户外家具'
                },
                {
                    value: '电器',
                    label: '电器'
                },
                {
                    value: '装饰公司',
                    label: '装饰公司'
                },
                {
                    value: '酒店家具',
                    label: '酒店家具'
                },
                {
                    value: '藤器',
                    label: '藤器'
                },
            ],
            FloorList:[
                {
                    value: '一楼',
                    label: '一楼'
                },
                {
                    value: '二楼',
                    label: '二楼'
                },
                {
                    value: '三楼',
                    label: '三楼'
                },
                {
                    value: '四楼',
                    label: '四楼'
                },
                {
                    value: '五楼',
                    label: '五楼'
                },
                {
                    value: '六楼',
                    label: '六楼'
                },
                {
                    value: '负一楼',
                    label: '负一楼'
                },
                {
                    value: '负二楼',
                    label: '负二楼'
                },
            ],
            StandTypeList:[
                {
                    value: '正常',
                    label: '正常'
                },
                {
                    value: '撤场中',
                    label: '撤场中'
                },
                {
                    value: '已撤场',
                    label: '已撤场'
                },
            ],
            BrandList:[],
            SeriesList:[],
            formRight: {
                StoreType: '',
                Store: '',
                Floor: '',
                ProductType: '',
                StandNo: '',
                StandName: '',
                StandType: '',
                StandArea: '',
                RuTime:'',
                ZsStore:'',
                ZsBm:'',
                ZsName:'',
                ResponsibleMan:'',
                Position:'',
                RPhoneNo:'',
                EndTime:'',
                EndReason:'',
                BrandName:'',
                SeriesName:''
            },
            //添加品牌、系列start
            modal1: false,
            BrandForm:{
                BrandName:"",
                SeriesName:""
            }
            //添加品牌系列end
        }
    },
    created(){
        var ID = this.oneValues();
        this.ID = ID;
        this.initThisPage();
        this.queryBrandList();
    },
    methods: {
        changeStore(){
            var self = this;
            self.formRight.Store = "";
            self.StoreList = new Array();
            if(self.formRight.StoreType=="东明店面"){
                self.StoreList = [{value: "东明东二环店", label: "东明东二环店"},{value: "东明建华店", label: "东明建华店"},{value: "东明金利来店", label: "东明金利来店"},{value: "东明北杜店", label: "东明北杜店"},{value: "东明西二环店", label: "东明西二环店"},{value: "东明北二环店", label: "东明北二环店"},{value: "东明蒂摩玛办公馆", label: "东明蒂摩玛办公馆"}];
            }else if(self.formRight.StoreType=="红星美凯龙"){
                self.StoreList = [{value: "红星方北店", label: "红星方北店"},{value: "红星和平店", label: "红星和平店"},{value: "红星中储店", label: "红星中储店"},{value: "红星西古城店", label: "红星西古城店"}];
            }else if(self.formRight.StoreType=="居然之家"){
                self.StoreList = [{value: "居然之家长安店", label: "居然之家长安店"}];
            }else if(self.formRight.StoreType=="怀特"){
                self.StoreList = [{value: "怀特家具城", label: "怀特家具城"},{value: "怀特红木楼", label: "怀特红木楼"},{value: "怀特建材城", label: "怀特建材城"},{value: "怀特陶瓷城", label: "怀特陶瓷城"}];
            }else if(self.formRight.StoreType=="米氏"){
                self.StoreList = [{value: "米氏中华店", label: "米氏中华店"}];
            }else if(self.formRight.StoreType=="蓝天"){
                self.StoreList = [{value: "蓝天圣木家具城", label: "蓝天圣木家具城"}];
            }else if(self.formRight.StoreType=="明月"){
                self.StoreList = [{value: "明月家具城", label: "明月家具城"},{value: "新明月北二环店", label: "新明月北二环店"},{value: "明月石铜路装饰材料市场", label: "明月石铜路装饰材料市场"},{value: "明月丰收路装饰材料市场", label: "明月丰收路装饰材料市场"}];
            }else if(self.formRight.StoreType=="正定金河"){
                self.StoreList = [{value: "金河家具城", label: "金河家具城"}];
            }else if(self.formRight.StoreType=="正定三才"){
                self.StoreList = [{value: "三才家具城", label: "三才家具城"}];
            }
        },
        initThisPage() {
            var self = this;
            var ID = self.ID;
            var jsondata = {"ID":ID};
            var data_json = JSON.stringify(jsondata)
            $.ajax({
                url: "./goSHGL/initZWEditPage", //请求的url地址
                dataType: "json", //返回格式为json
                async:false,
                data: data_json, //参数值
                type: "POST", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function(data) {
                    var formcontent = JSON.parse(data.data);
                    self.formRight.StoreType = formcontent.StoreType;
                    self.formRight.Store = formcontent.Store;
                    self.formRight.Floor = formcontent.Floor;
                    self.formRight.ProductType = formcontent.ProductType;
                    self.formRight.StandNo = formcontent.StandNo;
                    self.formRight.StandName = formcontent.StandName;
                    self.formRight.StandType = formcontent.Type;
                    self.formRight.StandArea = formcontent.StandArea;
                    self.formRight.RuTime = formcontent.RuTime;
                    self.formRight.ZsStore = formcontent.ZsStore;
                    self.formRight.ZsBm = formcontent.ZsBm;
                    self.formRight.ZsName = formcontent.ZsUserName;
                    self.formRight.ResponsibleMan = formcontent.ResponsibleMan;
                    self.formRight.Position = formcontent.Position;
                    self.formRight.RPhoneNo = formcontent.RPhoneNo;
                    self.formRight.EndTime = formcontent.EndTime;
                    self.formRight.EndReason = formcontent.EndReason;
                    // self.formRight.BrandName = formcontent.BrandName;
                    // self.formRight.SeriesName = formcontent.SeriesName;

                },
                error: function() {
                },
            });
        },
        queryBrandList(){
            var self = this;
            self.BrandList = [];
            self.formRight.BrandName = "";
            var ShNo = self.ShNo;
            var jsondata={"ShNo":ShNo};
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goSHGL/queryBrandList", //请求的url地址
                dataType: "json", //返回格式为json
                async:false,
                data: data_json, //参数值
                type: "POST", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function(data) {
                    var tempArr = new Array();
                    tempArr = data.BrandList;
                    for(var i=0;i<tempArr.length;i++){
                        var temp = {
                            label:tempArr[i].BrandName,
                            value:tempArr[i].BrandName
                        }
                        self.BrandList.push(temp);
                    }
                },
                error: function() {},
            });
        },
        changeSeries(){
            var self = this;
            self.SeriesList = [];
            self.formRight.SeriesName = "";
            var BrandName = self.formRight.BrandName;
            var jsondata={ "BrandName":BrandName};
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goSHGL/querySeriesByBrandName", //请求的url地址
                dataType: "json", //返回格式为json
                async:false,
                data: data_json, //参数值
                type: "POST", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function(data) {
                    var tempArr = new Array();
                    tempArr = data.SeriesList;
                    for(var i=0;i<tempArr.length;i++){
                        var temp = {
                            label:tempArr[i].SeriesName,
                            value:tempArr[i].BrandID
                        }
                        self.SeriesList.push(temp);
                    }
                },
                error: function() {},
            });
        },
        //添加品牌名称与系列名称
        saveBrandAndSeries(){
            var self = this;
            var BrandName = self.BrandForm.BrandName;
            var SeriesName = self.BrandForm.SeriesName;
            if(BrandName==null||BrandName.trim()==""){
                toastr.warning("请输入品牌名称");
            }
            if(SeriesName==null||SeriesName.trim()==""){
                toastr.warning("请输入系列名称");
            }
            var jsondata={ "BrandName":BrandName,"SeriesName":SeriesName};
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goSHGL/saveBrandAndSeries", //请求的url地址
                dataType: "json", //返回格式为json
                async:false,
                data: data_json, //参数值
                type: "POST", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function(data) {
                    if(data.status == "2"){
                        toastr.warning("保存失败，已有该品牌系列");
                    }
                    if(data.status == "1"){
                        toastr.warning("保存成功");
                        self.modal1 = false;
                        self.queryBrandList();
                    }
                    if(data.status == "0"){
                        toastr.warning("保存失败");
                    }
                    self.BrandForm.BrandName = "";
                    self.BrandForm.SeriesName = "";
                    return false;
                },
                error: function() {},
            });
        },
        //编辑展位信息
        updateZWInfos(){
            var self = this;
            var ID = self.ID;
            if(ID==null||ID==''){
                toastr.warning("展位ID未获取请重新刷新界面")
                return false;
            }
            if(self.formRight.StoreType==null||self.formRight.StoreType==""){
                toastr.warning("请选择店面分类");
                return false;
            }
            if(self.formRight.Store==null||self.formRight.Store==""){
                toastr.warning("请选择中心店面");
                return false;
            }
            if(self.formRight.Floor==null||self.formRight.Floor==""){
                toastr.warning("请选择楼层");
                return false;
            }
            if(self.formRight.ProductType==null||self.formRight.ProductType==""){
                toastr.warning("请选择产品品类");
                return false;
            }
           /* if(self.formRight.StandNo==null||self.formRight.StandNo.trim()==""){
                toastr.warning("请录入展位编号");
                return false;
            }*/
            if(self.formRight.StandName==null||self.formRight.StandName.trim()==""){
                toastr.warning("请录入展位名称");
                return false;
            }
            if(self.formRight.StandType==null||self.formRight.StandType==""){
                toastr.warning("请选择展位状态");
                return false;
            }
            if(self.formRight.StandArea==null||self.formRight.StandArea==""){
                toastr.warning("请录入展位面积");
                return false;
            }
            if(self.isMianJi(self.formRight.StandArea)){

            }else{
                toastr.warning("展位面积请填写两位小数以内的正数");
                return false;
            }
            if(self.formRight.RuTime!=null&&self.formRight.RuTime!=""){
                var tempzwrutime = new Date(self.formRight.RuTime);
                self.formRight.RuTime = tempzwrutime.toLocaleDateString();
            }else{
                self.formRight.RuTime = null;
            }

            /*if(self.formRight.ZsStore==null||self.formRight.ZsStore.trim()==""){
                toastr.warning("请录入招商人店面");
                return false;
            }
            if(self.formRight.ZsBm==null||self.formRight.ZsBm.trim()==""){
                toastr.warning("请录入招商人部门");
                return false;
            }
            if(self.formRight.ZsName==null||self.formRight.ZsName.trim()==""){
                toastr.warning("请录入招商人姓名");
                return false;
            }*/
            if(self.formRight.BrandName==null||self.formRight.BrandName==""){
                toastr.warning("请选择品牌名称");
                return false;
            }
            if(self.formRight.SeriesName==null||self.formRight.SeriesName==""){
                toastr.warning("请选择系列名称");
                return false;
            }

            if(self.formRight.RPhoneNo!=null&&self.formRight.RPhoneNo!=""){
                if(!self.isPoneAvailable(self.formRight.RPhoneNo)){
                    toastr.warning("请录入正确的负责人手机号");
                    return false;
                }

            }

            if(self.formRight.EndTime!=null&&self.formRight.EndTime!=""){
                var tempzwEndtime = new Date(self.formRight.EndTime);
                self.formRight.EndTime = tempzwEndtime.toLocaleDateString();
            }
            var zwInfos = self.formRight;
            zwInfos.ID = ID;
            var ShNo = self.formRight.ShNo;
            var data_json = JSON.stringify(zwInfos);
            $.ajax({
                url: "./goSHGL/editZWInfo", //请求的url地址
                dataType: "json", //返回格式为json
                async:false,
                data: data_json, //参数值
                type: "POST", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function(data) {
                    if(data.status == "1"){
                        toastr.warning("保存成功");
                        window.location.href="./sh_search.html";
                    }
                    if(data.status == "0"){
                        toastr.warning("保存失败");
                    }
                    return false;
                },
                error: function() {},
            });
        },
        oneValues(){
            var result;
            var url=window.location.search; //获取url中"?"符后的字串
            if(url.indexOf("?")!=-1){
                result = url.substr(url.indexOf("=")+1);
            }
            return result;
        },
        isMianJi(mj){
            var reg = /^[1-9]+\d*(\.\d{0,2})?$|^0?\.\d{0,2}$/;
            if(reg.test(mj)){
                return true;
            }else{
                return false;
            }
        },
        //手机号验证
        isPoneAvailable(str) {
            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        },
        ok () {
        },
        cancel () {
        },
        goBack(){
            window.location.href = "./sh_search.html"
        },
        editZWInfo(EndTime,EndReason,StandNo){
            if(EndTime==''||EndTime==null){
                toastr.warning("展位撤场日期不得为空");
                return false;
            }
            var tempEndTime = new Date(EndTime);
            EndTime = tempEndTime.toLocaleDateString();
            if(EndReason==''||EndReason==null){
                toastr.warning("展位撤场原因不得为空");
                return false;
            }
            var jsondata = {"EndTime":EndTime,"EndReason":EndReason,"StandNo":StandNo};
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goSHGL/editZWInfo", //请求的url地址
                dataType: "json", //返回格式为json
                async:false,
                data: data_json, //参数值
                type: "POST", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function(data) {
                    toastr.success("编辑成功")
                },
                error: function() {},
            });
        },
        delZWInfo(StandNo){
            var jsondata = {"StandNo":StandNo}
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goSHGL/delZWInfo", //请求的url地址
                dataType: "json", //返回格式为json
                async:false,
                data: data_json, //参数值
                type: "POST", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function(data) {
                    toastr.success("删除成功")
                    var select = "#"+StandNo;
                    $(select).attr("style","display:none");
                },
                error: function() {},
            });
        }
    }
})
